#include "dialog_bright.h"

#include "lcd_driver.h"
#include "key_driver.h"

BrightDialog::BrightDialog(HWND parent):PopupDialog (parent)
{
    name ="BrightDialog";
    
    setupWidgets();
}

BrightDialog::~BrightDialog()
{
    cleanWidgets();
}



/** @function setupWidgets
 *  @brief    setwidgets' parent to this
 *            draw widgets
 */
void BrightDialog::setupWidgets()
{
    setSize(80, 30);
    pButton1 = new Button(this, "UP");
    pButton1->setPosition(0,0);
    
    pButton2 = new Button(this, "DOWN");
    pButton2->setPosition(20,20);
    
    pButton3 = new Button(this, "OK");
    pButton3->setPosition(40,40);

    connect(&pButton1->signal[SIGNAL_BUTTON_UP], this);
    connect(&pButton2->signal[SIGNAL_BUTTON_UP], this);
    connect(&pButton3->signal[SIGNAL_BUTTON_UP], this);
}

void BrightDialog::cleanWidgets()
{
    delete pButton3;
    delete pButton2;
    delete pButton1;
}

void BrightDialog::draw(Rect *r)
{
    pDC->fillRect(r->x0, r->y0, r->x1, r->y1, 0x00);
    pDC->drawRect(rect.x0, rect.y0, rect.x1, rect.y1, 0x0F);
    
    pDC->dirty(max(r->x0,rect.x0), max(r->y0,rect.y0), min(r->x1,rect.x1), min(r->y1,rect.y1));
    Widget::draw(r);
}

void BrightDialog::buttonUp()
{
}

int BrightDialog::eventHandler(HWND hWnd, int iMsg, WPARAM wParam, LPARAM lParam)
{
    switch(iMsg)
    {
    case MSG_SIGNAL:
        if(SIGNAL_MATCH(wParam,  &pButton1->signal[SIGNAL_BUTTON_UP]) )
        {
            buttonUp();
        }
        if(SIGNAL_MATCH(wParam,  &pButton2->signal[SIGNAL_BUTTON_UP]) )
        {
            buttonUp();
        }
        if(SIGNAL_MATCH(wParam, &pButton3->signal[SIGNAL_BUTTON_UP]) )
        {
            close();
        }
        break;
    }

    PopupDialog::eventHandler(hWnd, iMsg, wParam, lParam);
}


